package ms.utils;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;


public class TreeNodeRenderer extends DefaultTreeCellRenderer {

	private static final long serialVersionUID = 1L;

	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row,
			boolean hasFocus) {

		super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

		Object nodeObj = ((DefaultMutableTreeNode) value).getUserObject();

		if (nodeObj instanceof TreeNodeData) {
			TreeNodeData data = (TreeNodeData) nodeObj;
			if (data.getIcon() != null)
				setIcon(data.getIcon());
		}

		return this;
	}
}